/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.ui.components;

import java.awt.image.ImageObserver;
import rpg.RPG;
import rpg.gfx.Bitmap;

/**
 *
 * @author rothens
 */
public class ComponentImageButton extends ComponentButton {
    
    Bitmap[] bitmaps;
    Bitmap[] texts;

    public ComponentImageButton(Integer x, Integer y, Bitmap[] buttonimages, String text, byte textId, int[] colors) {
        super(buttonimages[1].width, buttonimages[1].height, x, y);
        bitmaps = new Bitmap[buttonimages.length];
        texts = new Bitmap[buttonimages.length];
        for(int i = 0; i < buttonimages.length; i++){
            bitmaps[i] = new Bitmap(buttonimages[i].width, buttonimages[i].height).draw(buttonimages[i], 0, 0);
            Bitmap t = RPG.fs.getText(text, textId, colors[i%colors.length]);
            bitmaps[i].drawOn(t, width/2-t.width/2, height/2-t.height/2);
        }
    }
    
    public ComponentImageButton(Integer x, Integer y, Bitmap ... buttonimages) {
        super(buttonimages[1].width, buttonimages[1].height, x, y);
        bitmaps = new Bitmap[buttonimages.length];
        texts = new Bitmap[buttonimages.length];
        for(int i = 0; i < buttonimages.length; i++){
            bitmaps[i] = new Bitmap(buttonimages[i].width, buttonimages[i].height).draw(buttonimages[i], 0, 0);
        }
    }
    
    
    

    @Override
    public void redraw() {
        clear();
        switch(state){
            case INACTIVE:
                draw(bitmaps[0],0,0);
                break;
            case HOVER:
                if(bitmaps.length>2){
                    draw(bitmaps[2],0,0);
                    break;
                }
            default:
                if(bitmaps.length>1){
                    draw(bitmaps[1],0,0);
                } else {
                    draw(bitmaps[0],0,0);
                }
                break;
        }
        if(parent != null){
            ((Component)parent).redraw();
        }
        /*if(state == ComponentState.INACTIVE){
            draw(bitmaps[0],0,0);
        } else {
            draw(bitmaps[1],0,0);
        }*/
    }
    
}
